363A - Soroban - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
def valid(i,j,n,m):
        if i<n and i>=0 and j>=0 and j< m :return True         return  False
def sumn(i,n):
    return (n-i)*(i+n)/2
def sqfun(a,b,c):
    return (-b+math.sqrt(b*b-4*a*c))/2*a
def getprime(num):     
        if  all(num%i!=0 for i in range(2,int(math.sqrt(num))+1)):return  True
           


def value(): return tuple(map(int, input().split()))
def values(): return tuple(map(int, sys.stdin.readline().split()))
def inlst(): return [int(i) for i in input().split()]
def inlsts(): return [int(i) for i in sys.stdin.readline().split()]
def inp(): return int(input())
def inps(): return int(sys.stdin.readline())
def instr(): return input()
def stlst(): return [i for i in input().split()]



def solve():
    n = inp()
    for i in str(n)[::-1]:
        tmp=int(i)
        s=''
        if tmp>=5:
            s+='-O|'
            s+='O'*(tmp-5)+'-'
            s+='O'*(5-(tmp-5)-1)
        else:
            s+='O-|'
            s+='O'*(tmp)+'-'
            s+='O'*(5-(tmp)-1)
        print(s)





if __name__ == "__main__":
            solve()

C++ Code:

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    if(n==0)
    {
        cout<<"O-|-OOOO"<<"\n";
        return 0;
    }
    while(n)
    {
        int r=n%10;
        if(r>4)
        {
            cout<<"-O|";
            int l=r-5;
            int c=l;
            while(l>0)
            {
                cout<<"O";
                l--;
            }
            int m=4-c;
            cout<<"-";
            while(m>0)
            {
                cout<<"O";
                m--;
            }
        
        }
        else
        {
            cout<<"O-|";
            int l=4-r;
            int m=l;
            while(r>0)
            {
                cout<<"O";
                r--;
            }
          
            cout<<"-";
            while(m>0)
            {
                cout<<"O";
                m--;
            } 
        }
        n/=10;
        cout<<"\n";
    }
    cout<<"\n";
    return 0;
}


Comments

Submit
0 Comments
More Questions

1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers